package cn.hy.mygame;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import cn.hy.mygame.global.Config;
import cn.hy.mygame.tools.DeviceTools;
import cn.hy.mygame.view.GameView;
import cn.hy.mygame.view.TestGameView;

public class MyGameActivity extends Activity {
	private GameView gameView = null;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.main);
		
		initData();
		
		gameView = new GameView(this);
		setContentView(gameView);
	}
	
	private void initData(){
		Config.deviceWith = DeviceTools.getDeviceInfo(this)[0];
		Config.deviceHeight = DeviceTools.getDeviceInfo(this)[1];
		
		Bitmap gameBack = BitmapFactory.decodeResource(getResources(), R.drawable.bk);
		Config.scaleWidth = (float)Config.deviceWith / gameBack.getWidth();
		Config.scaleHeight = (float)Config.deviceHeight / gameBack.getHeight();
		
		Config.gameback = DeviceTools.resizeBitmap(gameBack);
		Config.seedBank = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.seedbank));
		Config.seedFlower = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.seed_flower), Config.seedBank.getWidth()/8, Config.seedBank.getHeight());
		Config.seedPea = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.seed_pea), Config.seedBank.getWidth()/8, Config.seedBank.getHeight());
		
		Config.sun = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.sun));
		Config.bullet = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.bullet));
		
		Config.flowerFrames[0] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_1_01));
		Config.flowerFrames[1] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_1_02));
		Config.flowerFrames[2] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_1_03));
		Config.flowerFrames[3] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_1_04));
		Config.flowerFrames[4] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_1_05));
		Config.flowerFrames[5] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_1_06));
		Config.flowerFrames[6] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_1_07));
		Config.flowerFrames[7] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_1_08));
		
		Config.PeaFrames[0] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_2_01));
		Config.PeaFrames[1] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_2_02));
		Config.PeaFrames[2] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_2_03));
		Config.PeaFrames[3] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_2_04));
		Config.PeaFrames[4] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_2_05));
		Config.PeaFrames[5] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_2_06));
		Config.PeaFrames[6] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_2_07));
		Config.PeaFrames[7] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.p_2_08));
		
		Config.zombieFrames[0] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.z_1_01));
		Config.zombieFrames[1] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.z_1_02));
		Config.zombieFrames[2] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.z_1_03));
		Config.zombieFrames[3] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.z_1_04));
		Config.zombieFrames[4] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.z_1_05));
		Config.zombieFrames[5] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.z_1_06));
		Config.zombieFrames[6] = DeviceTools.resizeBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.z_1_07));
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		Log.i("touch", "activity touch");
		return gameView.onTouchEvent(event);
	}
}